package com.luyuan.crm.sale.web.provider;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.luyuan.crm.product.model.Product;
import com.luyuan.crm.product.model.ProductType;
import com.luyuan.crm.product.service.ProductService;
import com.ruijie.web.jsf.provider.ComboboxItemsProvider;

@Component("productProvider")
public class ProductProvider implements ComboboxItemsProvider<Product> {
    @Resource(name = "productService")
    private ProductService productService;

    @Override
    public List<Product> getSuggestionItems(Object... parameters) {
        if (parameters == null || parameters.length == 0) {
            return productService.find("from Product where enabled = true");
        }

        return productService.findByProductType((ProductType) parameters[0]);
    }

}
